package leetcode.code1472;

public class BrowserHistory {

	String[] history;
	int cur, range;

	public BrowserHistory(String homepage) {
		history = new String[5000];// 最多调用 5000 次 visit， back 和 forward 函数。
		cur = -1;
		this.visit(homepage);
	}

	public void visit(String url) {
		history[++cur] = url;
		range = cur;
	}

	public String back(int steps) {
		cur = Math.max(0, cur - steps);
		return history[cur];
	}

	public String forward(int steps) {
		cur = Math.min(range, cur + steps);
		return history[cur];
	}

}
